﻿// Jinx AJAX Framework
// Copyright (C) 2008 Blake Hegerle
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using Jinx.Bindings;
using Jinx.Models;
using Jinx.Naming;
using NUnit.Framework;

namespace TestFramework.UnitTests.Bindings
{
    /*     F
     *    | |
     *    | |
     *    V V
     *     E  
     *    ^ |
     *    | |
     *    | V
     *    (D)
     *     |
     *     |
     *     V
     *     A
     *    ^ \
     *    |  \
     *    |   \ 
     *    |    V
     *    |    B
     *    |   /
     *    |  /
     *    | V
     *    (C)
     */

    public abstract class BindingTestBase
    {
        protected IOneRef A;
        protected ProxyModel<IOneRef> AModel;
        protected IOneRef B;
        protected BindingContext BindingContext;
        protected IOneRef C;
        protected ITwoRefs D;
        protected IOneRef E;
        protected ITwoRefs F;

        protected NamingContext NamingContext
        {
            get { return BindingContext.NamingContext; }
        }

        [SetUp]
        public void Setup()
        {
            BindingContext = new BindingContext();

            AModel = ModelFactory<IOneRef>.New();

            NamingContext.Context.Register(AModel);
            NamingContext.NameInContext(AModel, "A");

            A = AModel.GetProxyInterface();
            B = NamingContext.NameNew<IOneRef>("B");
            C = NamingContext.New<IOneRef>();
            D = NamingContext.New<ITwoRefs>();
            E = NamingContext.NameNew<IOneRef>("E");
            F = NamingContext.NameNew<ITwoRefs>("F");

            A.Ref = B;
            B.Ref = C;
            C.Ref = A;

            D.Ref1 = A;
            D.Ref2 = E;

            E.Ref = D;

            F.Ref1 = E;
            F.Ref2 = E;
        }

        #region Nested type: IBase

        public interface IBase
        {
            string Name { get; set; }
        }

        #endregion

        #region Nested type: IOneRef

        public interface IOneRef : IBase
        {
            IBase Ref { get; set; }
        }

        #endregion

        #region Nested type: ITwoRefs

        public interface ITwoRefs : IBase
        {
            IBase Ref1 { get; set; }
            IBase Ref2 { get; set; }
        }

        #endregion
    }
}